package com.swotxu.rttest.interceptor;

import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpRequest;

import java.net.URI;

/**
 * HttpRequest 封装类
 *
 * @Date: 2020/9/22 23:01
 * @Author: swotXu
 */
@Slf4j
public class MyHttpRequest implements HttpRequest {

    private HttpRequest sourceRequest;

    public MyHttpRequest(HttpRequest httpRequest) {
        this.sourceRequest = httpRequest;
    }

    @Override
    public HttpMethod getMethod() {
        return sourceRequest.getMethod();
    }

    @Override
    public String getMethodValue() {
        return sourceRequest.getMethodValue();
    }

    @Override
    public HttpHeaders getHeaders() {
        return sourceRequest.getHeaders();
    }

    /**
     * 转换 URI
     * @return
     */
    @Override
    public URI getURI() {
        try {
            return new URI("http://localhost:8080/hello");
        } catch (Exception e) {
            log.warn("URI地址转换失败！", e);
        }
        return sourceRequest.getURI();
    }
}
